import React from 'react';
import { Form, Input, Radio, Spin } from 'antd';
import { PlanInfoFormProps } from '../types';
import { FormField, VALIDATION_MESSAGES } from '../constants';
import styles from './index.less';

const { TextArea } = Input;

const PlanInfoForm: React.FC<PlanInfoFormProps> = ({ 
  planInfo, 
  onChange, 
  loading = false 
}) => {
  // 处理字段变更
  const handleFieldChange = (field: string, value: any) => {
    onChange({ [field]: value });
  };

  return (
    <Spin spinning={loading}>
      <div className={styles['form-section']}>
        <h3 className={styles['section-title']}>基本信息</h3>
        
        <Form layout="vertical">
          <div className={styles['form-row']}>
            <div className={styles['form-item']}>
              <Form.Item
                label="重要业务系统"
                required={false}
              >
                <Input 
                  value={planInfo.systemName}
                  readOnly
                  className={styles['form-control']}
                />
              </Form.Item>
            </div>
            
            <div className={styles['form-item']}>
              <Form.Item
                label="投产计划实施时间"
                required={true}
                rules={[{ required: true, message: VALIDATION_MESSAGES.REQUIRED }]}
              >
                <Input 
                  value={planInfo.implementationTime}
                  readOnly
                  className={styles['form-control']}
                />
              </Form.Item>
            </div>
          </div>
          
          <div className={styles['form-row']}>
            <div className={styles['form-item']}>
              <Form.Item
                label="本期是否申报投产规划"
                required={true}
                rules={[{ required: true, message: VALIDATION_MESSAGES.REQUIRED }]}
              >
                <Radio.Group 
                  value={planInfo.isReporting}
                  onChange={(e) => handleFieldChange(FormField.IS_REPORTING, e.target.value)}
                  className={styles['radio-group']}
                >
                  <Radio value={true}>申报投产规划</Radio>
                  <Radio value={false}>无需申报投产规划</Radio>
                </Radio.Group>
              </Form.Item>
            </div>
            
            <div className={styles['form-item']}>
              <Form.Item
                label="投产联系人"
                required={true}
                rules={[{ required: true, message: VALIDATION_MESSAGES.REQUIRED }]}
              >
                <Input 
                  value={planInfo.contactPerson}
                  readOnly
                  className={styles['form-control']}
                />
              </Form.Item>
            </div>
          </div>
          
          <Form.Item
            label="投产内容"
            required={true}
            rules={[{ required: true, message: VALIDATION_MESSAGES.REQUIRED }]}
          >
            <TextArea 
              value={planInfo.content}
              onChange={(e) => handleFieldChange(FormField.CONTENT, e.target.value)}
              rows={4}
              className={styles['form-control']}
            />
          </Form.Item>
          
          <Form.Item
            label="业务影响分析"
            required={true}
            rules={[{ required: true, message: VALIDATION_MESSAGES.REQUIRED }]}
          >
            <TextArea 
              value={planInfo.businessImpact}
              onChange={(e) => handleFieldChange(FormField.BUSINESS_IMPACT, e.target.value)}
              rows={4}
              className={styles['form-control']}
            />
          </Form.Item>
          
          <Form.Item
            label="其他说明"
          >
            <TextArea 
              value={planInfo.otherNotes}
              onChange={(e) => handleFieldChange(FormField.OTHER_NOTES, e.target.value)}
              rows={4}
              className={styles['form-control']}
            />
          </Form.Item>
        </Form>
      </div>
    </Spin>
  );
};

export default PlanInfoForm; 